package cn.com.lms.business.exam.web;

import cn.com.lms.business.core.constant.ErrorEnum;
import cn.com.lms.business.core.util.SystemUserUtil;
import cn.com.lms.business.exam.persistence.entity.PaperQuickScore;
import cn.com.lms.business.exam.service.PaperQuickScoreService;
import cn.com.lms.business.user.persistence.entity.SysUserVo;

import com.bnzj.core.exception.BusinessException;

import com.bnzj.core.rest.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author zhangzhenjiang
 * @createDate 2020/3/14
 * @description
 */
@Tag(name = "快捷设置分数", description = "快捷设置分数")
@RestController
@RequestMapping("/exam/paper/quick/score")
public class PaperQuickScoreController {

    @Autowired
    PaperQuickScoreService paperQuickScoreService;





    @GetMapping("/getQuickScore")
    public ResponseResult<PaperQuickScore> getQuickScore() {
       PaperQuickScore paperQuickScore=paperQuickScoreService.getQuickScore();

        return ResponseResult.success(paperQuickScore);
    }




    @Operation(summary = "更新")
    @PostMapping("/update")
    public ResponseResult<?> updatePaperQuickScore(@RequestBody PaperQuickScore paperQuickScore) {
        if (ObjectUtils.isEmpty(paperQuickScore.getId())) {
            throw new BusinessException(ErrorEnum.PARAMETER_CANNOT_BE_EMPTY.getMessage(), "" + ErrorEnum.PARAMETER_CANNOT_BE_EMPTY.getCode());
        }
        SysUserVo sysUser = SystemUserUtil.getCurrentUser();
        paperQuickScore.setModifyTime(new Date());
        paperQuickScore.setCreator(String.valueOf(sysUser.getId()));
        paperQuickScore.setCreateTime(new Date());
        paperQuickScore.setCreatorName(sysUser.getCname());
        paperQuickScoreService.updatePaperQuickScore(paperQuickScore);
        return ResponseResult.success();
    }


}
